package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.system.domain.SysAppVersion;
import com.ruoyi.system.service.ISysAppVersionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 程序版本Controller
 *
 * @author Felix
 * @date 2022-04-14
 */
@Api(tags = " 程序版本")
@RestController
@RequestMapping("/sysAppVersion")
public class SysAppVersionController extends BaseController {
    @Autowired
    private ISysAppVersionService sysAppVersionService;

    /**
     * 查询程序版本列表
     */
    @ApiOperation(value="查询程序版本列表", notes="查询程序版本列表")
    @PreAuthorize(hasPermi = "system:sysAppVersion:list")
    @GetMapping("/list")
    public TableDataInfo list(SysAppVersion sysAppVersion) {
        startPage();
        List<SysAppVersion> list = sysAppVersionService.selectSysAppVersionList(sysAppVersion);
        return getDataTable(list);
    }

    /**
     * 导出程序版本列表
     */
    @ApiOperation(value="导出程序版本列表", notes="导出程序版本列表")
    @PreAuthorize(hasPermi = "system:sysAppVersion:export")
    @Log(title = "程序版本", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAppVersion sysAppVersion) throws IOException {
        List<SysAppVersion> list = sysAppVersionService.selectSysAppVersionList(sysAppVersion);
        ExcelUtil<SysAppVersion> util = new ExcelUtil<SysAppVersion>(SysAppVersion.class);
        util.exportExcel(response, list, "程序版本数据");
    }
    /**
     * 获取程序版本详细信息
     */
    @ApiOperation(value="获取程序版本详细信息", notes="获取程序版本详细信息")
    @PreAuthorize(hasPermi = "system:sysAppVersion:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(sysAppVersionService.selectSysAppVersionById(id));
    }

    /**
     * 新增程序版本
     */
    @ApiOperation(value="新增程序版本", notes="新增程序版本")
    @PreAuthorize(hasPermi = "system:sysAppVersion:add")
    @Log(title = "程序版本", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAppVersion sysAppVersion) {
        return toAjax(sysAppVersionService.insertSysAppVersion(sysAppVersion));
    }

    /**
     * 修改程序版本
     */
    @ApiOperation(value="修改程序版本", notes="修改程序版本")
    @PreAuthorize(hasPermi = "system:sysAppVersion:edit")
    @Log(title = "程序版本", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAppVersion sysAppVersion) {
        return toAjax(sysAppVersionService.updateSysAppVersion(sysAppVersion));
    }

    /**
     * 删除程序版本
     */
    @ApiOperation(value="删除程序版本", notes="删除程序版本")
    @ApiImplicitParam(name = "ids", value = "程序版本ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "system:sysAppVersion:remove")
    @Log(title = "程序版本", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(sysAppVersionService.deleteSysAppVersionByIds(ids));
    }


    @ApiOperation(value="版本校验", notes="版本校验")
    @GetMapping("/checkVersion")
    public AjaxResult checkVersion(){
        SysAppVersion version = sysAppVersionService.selectMaxVersion();
        return AjaxResult.success(version);
    }



}
